# coding:utf-8

import sys
from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtGui import QPalette
from ui_2 import Ui_Dialog
from loguru import logger


class Qmy_2(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.pushButton_2.clicked.connect(self.on_pushButton_2_clicked)
        self.ui.chkBoxBold.toggled.connect(self.on_chkBoxBold_toggled)
        self.ui.radioButton.toggled.connect(self.on_radioButton_toggled)
        self.ui.radioButton_2.toggled.connect(self.on_radioButton_toggled)
        self.ui.radioButton_3.toggled.connect(self.on_radioButton_toggled)

    def on_pushButton_2_clicked(self):
        self.ui.textEdit.setText('hello world')

    def on_chkBoxBold_toggled(self, checked: bool) -> None:
        logger.info(f"triggered {checked}")
        # self.ui.textEdit.font().setBold(checked)    # 不能这样直接修改
        font = self.ui.textEdit.font()
        font.setBold(checked)
        self.ui.textEdit.setFont(font)

    def on_radioButton_toggled(self):
        # TextEdit 调色板
        plet = self.ui.textEdit.palette()
        if self.ui.radioButton.isChecked():
            plet.setColor(QPalette.Text, "Blue")
        elif self.ui.radioButton_2.isChecked():
            plet.setColor(QPalette.Text, "Red")
        else:
            plet.setColor(QPalette.Text, "Black")
        self.ui.textEdit.setPalette(plet)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Qmy_2()
    w.show()
    sys.exit(app.exec())
